import os,shutil,time,function
import mysql.connector

t0=time.time()

mydb = mysql.connector.connect(
  host="192.168.10.81",
  user="root",
  passwd="",
  database="xiaocheng"
)

pics=[]
mycursor = mydb.cursor()
mycursor.execute("select path,pic from pattern where operate='未处理' order by id asc limit 500")
myresult = mycursor.fetchall()
for x in myresult:
  try:
    shutil.copy(x[0],r'D:/Desk/系统图库/烫画集/1-待处理/'+x[1])
    pics.append(x[1])
  except:
    pass

print(time.time()-t0)
t0=time.time()

str="('"+"','".join(pics)+"')"
query = ("update pattern set operate='处理中' where pic in "+str)
mycursor.execute(query)
mydb.commit()
print(mycursor.rowcount, " 条记录更新")

print(time.time()-t0)
t0=time.time()

paths=function.get_file_paths("D:/Desk/系统图库/烫画集/1-待处理")
for path in paths:
  if os.path.isfile(path):
    shutil.move(path,r'D:/Desk/系统图库/烫画集/1-待处理/标注/'+os.path.basename(path))

print(time.time()-t0)
t0=time.time()

paths=function.get_file_paths("D:/Desk/系统图库/烫画集/1-待处理/标注/")
for path in paths:
  if os.path.isfile(path):
    shutil.copy(path,r'D:/Desk/系统图库/烫画集/1-待处理/图案/'+os.path.basename(path))

print(time.time()-t0)
t0=time.time()